package org.zn.note.jdk.beans;

import java.lang.reflect.Method;

/**
 * @ClassName MerchantServiceImpl
 * @Author zn
 * @Date 2019/11/22 22:20
 **/
public class MerchantServiceImpl extends AbstractService implements IMerchantService {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        IMerchantService merchantService = (IMerchantService) Class.forName("org.zn.note.jdk.beans.MerchantServiceImpl").newInstance();
        merchantService.service(null);
    }

    private static void test() {
        IMerchantService merchantService = new MerchantServiceImpl();
        merchantService.service(null);

        String s = "FinishOrderFacadeServiceImpl";

        String sTmp = s.substring(0, s.indexOf("FacadeServiceImpl"));
        sTmp = sTmp.substring(0, 1).toLowerCase() + sTmp.substring(1);
        System.out.println(sTmp);
        System.out.println("------------------------------------------");
        Class clz = MerchantInfo.class;
        Method[] methods = clz.getMethods();
        for (Method method : methods) {
            String methodName = method.getName();
            if (methodName.startsWith("set")) {
                System.out.print(methodName + "       ");
                System.out.println(cvtFmt(methodName));
            }
        }
    }

    private static String cvtFmt(String s) {
        StringBuilder buffer = new StringBuilder();
        s = s.substring(3); // del "set"
        String[] arr = s.split("_");
        for (int i = 0; i < arr.length; i++) {
            if (0 == i) {
                buffer.append(firstCharLowerCase(arr[i]));
            } else {
                buffer.append(firstCharUpperCase(arr[i]));
            }
        }
        return buffer.toString();
    }

    private static String firstCharUpperCase(String s) {
        return s.substring(0, 1).toUpperCase() + s.substring(1);
    }

    private static String firstCharLowerCase(String s) {
        return s.substring(0, 1).toLowerCase() + s.substring(1);
    }
}
